/*
 * Copyright 2013 Nikolay Todorov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jobinsight;
import javax.swing.table.*;
import java.util.ArrayList;
import java.util.List;

public class ViewerTableModel extends AbstractTableModel {
	List<ViewerData> list = new ArrayList();

	protected String[] columnNames = new String[] { "Key", "Value" };

	protected Class[] columnClasses = new Class[] { ViewerData.class, ViewerData.class };

	public void setData(List<ViewerData> list) {
		this.list = list;
	}

	// These are easy methods
	public int getColumnCount() {
		return columnClasses.length;
	}

	public int getRowCount() {
		return list.size();
	}

	// Information about each column
	public String getColumnName(int col) {
		return columnNames[col];
	}

	public Class getColumnClass(int col) {
		return columnClasses[col];
	}

	// The method that must actually return the value of each cell
	public Object getValueAt(int row, int col) {
		return list.get(row);
//		switch (col) {
//		case 0:
//			return list.get(row).getKey();
//		case 1:
//			return list.get(row).getValue();
//		default:
//			return null;
//		}
	}

	/**
	 * Returns true if the cell at row and column is editable
	 * 
	 * @param row
	 * @param column
	 * @return true if the cell is editable
	 */
	public boolean isCellEditable(int row, int column) {
		return column > 0;
	}

	public Object getObjectAtRow(int row) {
		return list.get(row).getObject();
	}
}


